package com.example.knowing_project.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.knowing_project.mapper.UserMapper;
import com.example.knowing_project.pojo.User;
import com.example.knowing_project.pojo.req.UserQueryReq;
import com.example.knowing_project.pojo.resp.PageResp;
import com.example.knowing_project.pojo.resp.UserQueryResp;
import com.example.knowing_project.service.UserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author Administrator
 * @description 针对表【user(用户)】的数据库操作Service实现
 * @createDate 2023-10-01 11:20:17
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User>
        implements UserService {
    @Resource
    private UserMapper userMapper;

    public PageResp<UserQueryResp> listUser(UserQueryReq req) {
//        if (!Objects.isNull(req.getLoginName())) {
//
//        }
        Page<User> userQueryRespPage = new Page<>(req.getPage(),
                req.getSize());

        Page<User> userPage = userMapper.selectPage(userQueryRespPage,null );

        System.out.println(userPage.getRecords()+"                                  ------------");
        List<User> records = userPage.getRecords();
        log.debug(records+" records");
        List<UserQueryResp> userQueryResps = BeanUtil.copyToList(records, UserQueryResp.class);
        PageResp<UserQueryResp> userQueryRespPageResp = new PageResp<>();
        userQueryRespPageResp.setTotal(userPage.getTotal());
        userQueryRespPageResp.setList(userQueryResps);

        return userQueryRespPageResp;

    }
}




